package top.fangw.tenant.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.fangw.common.core.result.Result;
import top.fangw.tenant.pojo.dto.MenuInfoQueryDto;
import top.fangw.tenant.pojo.entity.MenuInfo;
import top.fangw.tenant.pojo.vo.SysMenuInfoVO;
import top.fangw.tenant.service.IMenuInfoService;

import java.util.List;

/**
 * <p>
 * 用途：用于管理系统中的菜单信息 前端控制器
 * </p>
 *
 * @author fangw
 * @since 2024-02-18
 */
@Tag(name = "系统菜单信息管理")
@RestController
@RequestMapping("/menu-info")
@RequiredArgsConstructor
public class MenuInfoController {

    private final IMenuInfoService menuService;

    @Operation(summary = "添加菜单信息")
    @PostMapping("/add")
    public Result<?> add(@RequestBody MenuInfo menuInfo){
        menuService.add(menuInfo);
        return Result.success();
    }

    @Operation(summary = "修改菜单信息")
    @PutMapping("/update")
    public Result<?> update(@RequestBody MenuInfo menuInfo){
        menuService.add(menuInfo);
        return Result.success();
    }

    @Operation(summary = "删除菜单信息")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam String id){
        menuService.delete(id);
        return Result.success();
    }

    @Operation(summary = "根据菜单id查询菜单信息")
    @GetMapping("/detail")
    public Result<MenuInfo> detail(@RequestParam String id){
        MenuInfo menuInfo = menuService.getById(id);
        return Result.success(menuInfo);
    }

    @Operation(summary = "查询树结构")
    @GetMapping("/treeList")
    public Result<List<MenuInfo>> page(){
        List<MenuInfo> res = menuService.treeList();
        return Result.success(res);
    }

    @Operation(summary = "查询树结构")
    @PostMapping("/getListPage")
    public Result<?> getListPage(@RequestBody MenuInfoQueryDto menuInfoQueryDto){
        IPage<MenuInfo> res = menuService.getListPage(menuInfoQueryDto);
        return Result.success(res);
    }
}